//
//  ViewController.m
//  TableView
//
//  Created by mac on 16-3-4.
//  Copyright (c) 2016年 hyd. All rights reserved.
//

#import "ViewController.h"
//1.遵循数据源协议
@interface ViewController ()<UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];	// Do any additional setup after loading the view, typically from a nib.
    
    
    //2.设置数据源
    self.tableView.dataSource = self;
    
}
//协议中方法的实现
//1.返回tableView组数
//section组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //设置tableView有三组
    return 3;


}
//返回行数(每一组的行数)row行a
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //return 3;
    if (section == 0) {
        return 1;
    }else if (section == 1)
    {   return 2;
        
    }else{
        return 3;
    }

}

//3.将数据加载到每一行测cell
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //UItableViewCell:每一行的格子
    //IndexPath:代表唯一的一行
    //IndexPath有两个属性: section.row
    //IndexPath.section: 获取到组号0，1，2
    //IndexPath.row:获取行号
    
    //1.创建cell
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    
    //2.设置数据到cell
    //cell.textLabel.text = @"我的第一个tableView";
    //cell.imageView.image = [UIImage imageNamed:@"16.jpg"];
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"宝马";
        }
    }else if (indexPath.section == 1)
    {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"兰博基尼";
        }
        else
        {
            cell.textLabel
            .text= @"乔丹";
        
        }
    }else if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"康乃馨";
        }
    }else if (indexPath.section == 1)
    {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"百合";
        }
    }else{
        cell.textLabel.text = @"🌹玫瑰";
    
    }

    
    //3.返回cell
    return cell;
}

//4.给每一组添加头部标签
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"汽车类";
    }else if (section == 1)
    {
        return @"鞋子类";
    }else{
    
        return @"鲜花类";
    }

}
//5.给每一组添加脚本标签
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{

    if (section == 0) {
        return @"这类汽车好酷";
    }else if (section == 1)
    {
        return @"这类鞋子很漂亮";
    
    }else{
    return @"这类鲜花好香";
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    
}

@end
